package com.forum.module.system.controller.admin.feedback;

import cn.hutool.core.collection.CollUtil;
import com.forum.framework.common.pojo.DataResult;
import com.forum.framework.common.pojo.PageResult;
import com.forum.module.system.controller.admin.feedback.vo.FeedBackPageReqVO;
import com.forum.module.system.controller.admin.feedback.vo.FeedBackRespVO;
import com.forum.module.system.controller.admin.feedback.vo.FeedBackSavaReqVO;
import com.forum.module.system.controller.admin.role.vo.RolePageReqVO;
import com.forum.module.system.controller.admin.role.vo.RoleRespVO;
import com.forum.module.system.controller.admin.role.vo.RoleSaveReqVO;
import com.forum.module.system.convert.feedback.FeedBackConvert;
import com.forum.module.system.convert.role.RoleCovert;
import com.forum.module.system.dal.dataobject.feedback.FeedBackDO;
import com.forum.module.system.dal.dataobject.role.RoleDO;
import com.forum.module.system.service.feedback.FeedBackService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import static com.forum.framework.common.pojo.DataResult.success;

/**
 * 功能:
 * 作者:ouyzh
 * 日期:2025/3/19 20:55
 */
@RestController
@Tag(name = "管理后台 -- 用户反馈")
@RequestMapping("/system/feedback")
public class FeedBackController {
    private final FeedBackService feedBackService;

    public FeedBackController(FeedBackService feedBackService) {
        this.feedBackService = feedBackService;
    }

    @PostMapping("/create")
    @Operation(summary = "新增用户反馈")
    public DataResult<Long> createFeedBack(@RequestBody FeedBackSavaReqVO reqVO) {
        Long id = feedBackService.createFeedBack(reqVO);
        return success(id);
    }

    @PutMapping("/update")
    @Operation(summary = "更新用户反馈")
    public DataResult<Boolean> updateFeedBack(@RequestBody FeedBackSavaReqVO reqVO) {
        feedBackService.updateFeedBack(reqVO);
        return success(true);
    }

    @PostMapping("/page")
    @Operation(summary = "分页查询用户反馈列表")
    public DataResult<PageResult<FeedBackRespVO>> page(@RequestBody @Valid FeedBackPageReqVO pageReqVO) {
        // 获得角色分页列表
        PageResult<FeedBackDO> pageResult = feedBackService.getFeedBackPage(pageReqVO);
        if (CollUtil.isEmpty(pageResult.getList())) {
            return success(new PageResult<>(pageResult.getTotal()));
        }

        return success(new PageResult<>(FeedBackConvert.INSTANCE.covertList(pageResult.getList()), pageResult.getTotal()));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除用户反馈")
    @Parameter(name = "id", description = "用户反馈编号", required = true, example = "1024")
    public DataResult<Boolean> deleteFeedBack(@RequestParam("id") Long id) {
        feedBackService.deleteById(id);
        return success(true);
    }
}
